/**
 * 
 */
package com.bj58.data.hadoop.info.tools;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.apache.hadoop.io.Text;

/**
 * @author zhangpeng
 *
 */
public class InfoString {
	
	private static final SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd"); 
	private static final SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd"); 
	
	/**
	 * 字符串分割
	 * @param value
	 * @return
	 */
	public static String[] getInfoArray(String value)
	{
		return value.split("\\|");
	}
	
	/**
	 * 字符串分割
	 * @param value
	 * @return
	 */
	public static String[] getInfoArray(Text value)
	{
		return getInfoArray(value.toString());
	}
	
	/**
	 * 将日志中的时间转化为当前的日志yyyyMMdd
	 * @param time
	 * @return
	 */
	public static String formatTime(String currentTime)
	{
		String rowKeyTime = null;
		try {
			rowKeyTime = formatter1.format(formatter2.parse(currentTime));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rowKeyTime;
	}
	
	/**
	 * 获取月份yyyyMM
	 * @param currentTime
	 * @return
	 */
	public static String getMonth(String currentTime)
	{
		String rowKeyTime = null;
		try {
			rowKeyTime = formatter1.format(formatter2.parse(currentTime));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rowKeyTime.substring(0,6);
	}
}
